<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head>
    <th:block th:include="include :: header('车队工作记录列表')"/>
</head>
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <div class="col-sm-12 search-collapse">
            <form id="formId" class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">工单号：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="orderId" placeholder="请输入工单号"
                               class="layui-input" lay-required/>
                    </div>
                    <!--                    <label class="layui-form-label">车辆标识：</label>-->
                    <!--                    <div class="layui-input-inline">-->
                    <!--                        <input type="text" name="carId" placeholder="请输入车辆标识"-->
                    <!--                               class="layui-input" lay-required/>-->
                    <!--                    </div>-->
                    <label class="layui-form-label">创建人：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="createBy" placeholder="请输入创建人"
                               class="layui-input" lay-required/>
                    </div>
                    <label class="layui-form-label">更新人：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="updateBy" placeholder="请输入更新人"
                               class="layui-input"/>
                    </div>
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="car-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<div class="layui-card">
    <div class="layui-card-body">
        <table id="car-table" lay-filter="car-table"></table>
        <script type="text/html" id="car-toolbar">
            <button sec:authorize="hasPermission('/work/car/add','work:car:add')"
                    class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
                <i class="layui-icon layui-icon-add-1"></i>
                新增
            </button>
            <button sec:authorize="hasPermission('/work/car/remove','work:car:remove')"
                    class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
                <i class="layui-icon layui-icon-delete"></i>
                删除
            </button>
        </script>
        <script type="text/html" id="car-bar">
            <button sec:authorize="hasPermission('/work/car/edit','work:car:edit')"
                    class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i
                    class="layui-icon layui-icon-edit"></i>
            </button>
            <button sec:authorize="hasPermission('/work/car/remove','work:car:remove')"
                    class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i
                    class="layui-icon layui-icon-delete"></i>
            </button>
        </script>
        <!--图片预览-->
        <script id="file-image" type="text/html">
            {{#if(d.content != null && d.content != ''){ }}
            <a href="javascript:void(0);" class="pear-text">查看</a>
            {{# } }}
        </script>
        <!--序号-->
        <script id="index" type="text/html">
            <span>{{d.LAY_TABLE_INDEX + 1}}</span>
        </script>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script>
    layui.use(['table', 'form', 'jquery', 'dictionary'], function () {
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;

        let prefix = "/work/car/";

        let cols = [
            [
                {type: 'checkbox'},
                {
                    field: 'index',
                    title: '序号',
                    templet: "#index"
                },
                // {
                //     field: 'id',
                //     title: '标识'
                // },
                {
                    field: 'orderId',
                    title: '工单号'
                },
                // {
                //     field: 'carId',
                //     title: '车辆标识'
                // },
                // {
                //     field: 'content',
                //     title: '图片信息'
                // },
                {
                    field: 'show',
                    title: '图片详情',
                    templet: "#file-image",
                    event: "file-image"
                },
                {
                    field: 'createBy',
                    title: '创建人'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                // {
                //     field: 'updateBy',
                //     title: '更新人'
                // },
                // {
                //     field: 'updateTime',
                //     title: '更新时间'
                // },
                {title: '操作', toolbar: '#car-bar', align: 'center', width: 130}
            ]
        ]

        table.render({
            elem: '#car-table',
            url: prefix + 'data',
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#car-toolbar',
            defaultToolbar: [{
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter', 'print', 'exports']
        });

        table.on('tool(car-table)', function (obj) {
            debugger
            if (obj.event === 'remove') {
                window.remove(obj);
            } else if (obj.event === 'edit') {
                window.edit(obj);
            } else {
                window.show(obj);
            }
        });

        table.on('toolbar(car-table)', function (obj) {
            if (obj.event === 'add') {
                window.add();
            } else if (obj.event === 'refresh') {
                window.refresh();
            } else if (obj.event === 'batchRemove') {
                window.batchRemove(obj);
            }
        });

        form.on('submit(car-query)', function (data) {
            table.reload('car-table', {where: data.field})
            return false;
        });

        window.add = function () {
            layer.open({
                type: 2,
                title: '新增车队工作记录',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'add'
            });
        }

        window.edit = function (obj) {
            layer.open({
                type: 2,
                title: '修改车队工作记录',
                shade: 0.1,
                area: ['550px', '500px'],
                content: prefix + 'edit?id=' + obj.data['id']
            });
        }

        //预览多图
        window.show = function (obj) {
            debugger
            let content = obj.data.content;
            if (content != null && content != '') {
                if (JSON.parse(content).out==undefined) {
                    layer.msg("没有图片显示", {icon: 3, time: 1000});
                }
                let ids = JSON.parse(JSON.parse(content).out).ids;
                let imgArr = [];
                for (let i = 0; i < ids.length; i++) {
                    let fileId = ids[i]; //图片id
                    let image = "/system/file/download/" + fileId;
                    let img = {};
                    img.src = image;
                    imgArr.push(img);
                }
                layer.photos({
                    photos: {
                        "title": "预览图片",
                        "start": 0,
                        "data": imgArr
                    }
                    , anim: 5
                });
            }
        }

        window.remove = function (obj) {
            layer.confirm('确定要删除该车队工作记录', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "remove/" + obj.data['id'],
                    dataType: 'json',
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                obj.del();
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.batchRemove = function (obj) {
            let data = table.checkStatus(obj.config.id).data;
            if (data.length === 0) {
                layer.msg("未选中数据", {icon: 3, time: 1000});
                return false;
            }
            let ids = "";
            for (let i = 0; i < data.length; i++) {
                ids += data[i].id + ",";
            }
            ids = ids.substr(0, ids.length - 1);
            layer.confirm('确定要删除这些车队工作记录', {icon: 3, title: '提示'}, function (index) {
                layer.close(index);
                let loading = layer.load();
                $.ajax({
                    url: prefix + "batchRemove",
                    dataType: 'json',
                    data: {"ids": ids},
                    type: 'delete',
                    success: function (result) {
                        layer.close(loading);
                        if (result.success) {
                            layer.msg(result.msg, {icon: 1, time: 1000}, function () {
                                table.reload('car-table');
                            });
                        } else {
                            layer.msg(result.msg, {icon: 2, time: 1000});
                        }
                    }
                })
            });
        }

        window.refresh = function (param) {
            table.reload('car-table', {where: param});
        }
    })
</script>
</body>
</html>